'''
headers里面的键、值对动态加密
header设置方式：1、header['键']='值' 2、setrequestheader('键','值')

'''
import subprocess
import Regular
import hmac
import hashlib
import requests
def hmac_sha512(key, message):
    hmac_obj = hmac.new(key, message, hashlib.sha512)
    digest = hmac_obj.digest()
    return digest
def decode1():#------------------python中解密，
    for i in range(1, 3):
        page = [str(i)]
        result = subprocess.run(['node', 'qcc2.js'] + page, capture_output=True, text=True)
        a = re.findall(r"'(.*?)'", result.stdout)

        res1 = hmac_sha512(a[1].encode('utf-8'), a[0].encode('utf-8'))
        res2 = hmac_sha512(a[1].encode('utf-8'), a[2].encode('utf-8'))
        hmac_hex1 = res1.hex()[8:28]
        hmac_hex2 = res2.hex()
        print(hmac_hex1, hmac_hex2)
def decode2():#------------------js中解密
    for i in range(1,3):
        page=[str(i)]
        result = subprocess.run(['node', 'qcc2.js']+page, capture_output=True, text=True,encoding='utf-8')
        a = re.findall(r'[a-zA-Z0-9]+', result.stdout)
        print(a)
        request(a[0],a[1],page)
def request(hmac_hex1, hmac_hex2,page):
    headers = {
        str(hmac_hex1): str(hmac_hex2),  # --------------------------------
        # "accept": "application/json, text/plain, */*",
        # "accept-language": "zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6",
        # "cache-control": "no-cache",
        # "pragma": "no-cache",
        # "priority": "u=1, i",
        # "referer": "https://www.qcc.com/firm/6b242b475738f45a4dd180564d029aa9.html",
        # "sec-ch-ua": "\"Not A(Brand\";v=\"8\", \"Chromium\";v=\"132\", \"Microsoft Edge\";v=\"132\"",
        # "sec-ch-ua-mobile": "?0",
        # "sec-ch-ua-platform": "\"Windows\"",
        # "sec-fetch-dest": "empty",
        # "sec-fetch-mode": "cors",
        # "sec-fetch-site": "same-origin",
        "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/132.0.0.0 Safari/537.36 Edg/132.0.0.0",
        # "x-pid": "7c753a0a154fc7edf9ee53892d8a3aed",
        # "x-requested-with": "XMLHttpRequest"
    }
    params = {
        "isNewAgg": "true",
        "keyNo": "6b242b475738f45a4dd180564d029aa9",
        "pageIndex": page
    }
    response = requests.get(url, headers=headers, cookies=cookies, params=params)

    print(response.text)
    print(response)
if __name__ == '__main__':
    cookies = {
        # "qcc_did": "e0021f18-50a9-43b2-af46-96b2acaa9ea5",
        # "UM_distinctid": "194efa67bd01cfe-03f2b0c72cad62-4c657b58-146d15-194efa67bd12bc4",
        # "acw_tc": "1a0c39d117392578976572236e0037f5c58e448a91e48a340c0a77acebd38f",
        "QCCSESSID": "efd28aa2de45bad249f1e6e30f",  # --------------------------------
        # "tfstk": "go0Z6NNL1FLwPP0wnW4VzwsL4zUTRPv5uqwbijc01R2G5N6mYjMx5ovT5qkUW2i1lR9TujD7uL9WPUGt6oUDFLNJmpK3oSYbnHZGsiWJlL9WPea1awuHFAilPwCUMJVgil4DTWVuwrXcSx23x7V5Ir4mnBr3N5bGjrVGtk2Lir2mnrAEtbriD0f_GlADW_mXDBgQb8cgLalK85q1Xf2FoZ0EYlyl3J7co2PZOe-wTa-bE0e_V8HHRNzqtSkUVcJP7xlmwmqEuOAsEjDt8PUycCErxDi7bDJGuJg_gu40YsbmTyyKU2akr9PKxfimWA5Vo53sPoy8YIbYcy07q0DNMQh3SSDY2q9RWRcmw4n7zFW8_Dcz8gklHWqiFqnNnirg9WyWTBrh9OktSF6eCiIYXpVUFC4dDiEg9WyWTBSADlp3T8OgJ",
        # "CNZZDATA1254842228": "861314818-1739187453-https%253A%252F%252Fwww.qcc.com%252F%7C1739257948"
    }
    url = "https://www.qcc.com/api/datalist/touzilist"
    decode2()